package com.ui;

import javax.swing.*;
import java.awt.event.*;
import java.util.Objects;

public class zhuce extends JDialog {
    private JPanel contentPane;
    private JButton button_zhuce;
    private JButton buttonCancel2;
    private JTextField ID_Field1;
    private JTextField Pas_Field1;
    private JTextField Pas_A_Field1;
    private JLabel Yz_filde1;
    private JTextField YZ_Field1;

    public zhuce() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(button_zhuce);

        button_zhuce.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
        String ID=ID_Field1.getText();
        String psw=Pas_Field1.getText();
        String npsw=Pas_A_Field1.getText();
        if(!Objects.equals(npsw, psw))
        {
            return;
        }
        DENGLU.c.get(ID,psw);
        DENGLU.c.rigister();
        // 在此处添加您的代码
        //dispose();
    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public static void main() {
        zhuce dialog = new zhuce();
        dialog.pack();
        dialog.setVisible(true);
        //System.exit(0);
    }
}
